package com.ds.msg.mqtt.topic;

import com.ds.annotation.MethodChinaName;
import com.ds.config.ResultModel;
import com.ds.jds.core.esb.EsbUtil;
import com.ds.msg.mqtt.command.cmd.CreateTopicCommand;
import com.ds.msg.mqtt.command.cmd.SubscriptTopicCommand;
import com.ds.msg.mqtt.command.cmd.UnSubscriptTopicCommand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/api/mqtt/topic/")
@MethodChinaName(cname = "消息服务")
public class TopicAPI implements TopicService {


    @Override
    @RequestMapping(method = {RequestMethod.POST}, value = {"subscriptTopic"})
    public ResultModel<SubscriptTopicCommand> subscriptTopic(String topic) {
        return getService().subscriptTopic(topic);
    }


    @RequestMapping(method = {RequestMethod.POST}, value = {"unSubscriptTopic"})
    public ResultModel<UnSubscriptTopicCommand> unSubscriptTopic(String topic) {
        return getService().unSubscriptTopic(topic);
    }


    @RequestMapping(method = {RequestMethod.POST}, value = {"createTopic"})
    public ResultModel<CreateTopicCommand> createTopic(String topic, Boolean retained, Integer qos) {
        return getService().createTopic(topic, retained, qos);
    }



    <T> TopicService getService() {
        return (TopicService) EsbUtil.parExpression(TopicService.class);
    }

}
